class Solution {
public:
    int numberOfArithmeticSlices(vector<int>& A) {
        if(A.size()==0){
            return 0;
        }
        int count=2;
        int sum=0;
        //A.push_back(0);
        for(int i=1;i<A.size()-1;i++){
            if(A[i]-A[i-1]==A[i+1]-A[i]){
                count++;
            } else{
                sum=sum+(count-1)*(count-2)/2;
                //cout<<(count-1)*(count-2)/2<<" "<<sum<<endl;
                count=2;
            }
        }
        sum=sum+(count-1)*(count-2)/2;
        return sum;
    }
};


class Solution {
public:
    int numberOfArithmeticSlices(vector<int>& A) {
        if(A.size()<3){
            return 0;
        }
        vector<int> dp(A.size(),0);
        for(int i=2;i<A.size();i++){
            if(A[i]+A[i-2]==2*A[i-1]){
                dp[i]=dp[i-1]+1;
            }
        }
        
        return accumulate(dp.begin(),dp.end(),0);
    }
};